package org.spindle.dungeon.rooms;

import org.spindle.dungeon.EntityManager;
import org.spindle.dungeon.entities.GeneralEntity;
import org.spindle.dungeon.entities.Lever;
import org.spindle.dungeon.entities.Spawner;

public class LeverRoom extends GeneralRoom {

    private int numLevers = 3;

    public LeverRoom(int x, int y, int numLevers) {
        super(x, y);
        this.numLevers = numLevers;
        generate();
        addLevers();
    }

    private void addLevers() {
        GeneralEntity lever = null;
        for (int i = 0; i < numLevers; i++) {
            lever = new Lever();
            lever.x = x + 64 + i * 32;
            lever.y = y + 48;
            EntityManager.getInstance().registerEntity(lever);
        }

        GeneralEntity spawner = new Spawner();
        spawner.x = x + (numLevers * 6 * 16 / 2);
        spawner.y = y + (10 * 16);
        EntityManager.getInstance().registerEntity(spawner);

        lever.triggerables.add(spawner);
    }

    @Override
    public int[][] getRoom() {
        int height = 20;
        int width = numLevers * 5 + 4;
        int[][] room = new int[height + 2][width + 1];


        for (int j = 0; j <= height - 1; j++) {
            for (int i = 0; i <= width; i++) {
                if (j == height - 1) {
                    room[j][i] = 2;
                } else if (i == 0 || j == 0 || j == height - 1 || i == width) {
                    room[j][i] = 0;
                } else if ((i > 0 && i < 3) && j > height / 2 - 2 && j < height / 2 + 2) {
                    if (j == height / 2 - 1) {
                        room[j][i] = 2;
                    } else {
                        room[j][i] = 0;
                    }
                } else if ((i > 0 && i < 3) || (i > width - 3 && i < width) || (j > 0 && j < 3) || (j > height - 4 && j < height - 1)) {
                    room[j][i] = 1;
                } else if (i > 2 && i < width - 2 && j == 3) {
                    room[j][i] = 2;
                }
                //else if ((i>4 && i<width-4) && (j==4 || j<width-1)) {
                //    room[j][i]=2;
                //}
            }
        }

        return room;
    }
}
